package com.slz.crm.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.slz.crm.common.result.Result;
import com.slz.crm.pojo.dto.BusinessActivityUserDTO;
import com.slz.crm.pojo.vo.BusinessActivityUserVO;
import com.slz.crm.server.service.BusinessActivityUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/activity/user")
public class BusinessActivityUserController {

    @Autowired
    private BusinessActivityUserService businessActivityUserService;

    /**
     * 创建活动用户关联
     * @param dto 活动用户关联DTO
     * @return 是否创建成功
     */
    @PostMapping
    public Result<Boolean> create(@RequestBody BusinessActivityUserDTO dto) {
        return Result.success(businessActivityUserService.create(dto));
    }

    /**
     * 删除活动用户关联
     * @param idList 关联ID列表
     * @return 是否删除成功
     */
    @DeleteMapping
    public Result<Integer> delete(@RequestBody List<Long> idList) {
        return Result.success(businessActivityUserService.deleteByIds(idList));
    }

    /**
     * 更新活动用户关联
     * @param businessActivityUserDTOList 活动用户关联DTO列表
     * @return 成功更新的数量
     */
    @PutMapping
    public Result<Integer> update(@RequestBody List<BusinessActivityUserDTO> businessActivityUserDTOList) {
        return Result.success(businessActivityUserService.updateList(businessActivityUserDTOList));
    }

    /**
     * 获取所有活动用户关联
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @return 活动用户关联列表
     */
    @GetMapping
    public Result<List<BusinessActivityUserVO>> getAll(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return Result.success(businessActivityUserService.getAll(pageNum, pageSize));
    }

    /**
     * 自定义分页查询活动用户关联列表
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @param dto 查询条件DTO
     * @return 活动用户关联列表
     */
    @PostMapping("/query")
    public Result<Page<BusinessActivityUserVO>> query(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestBody BusinessActivityUserDTO dto) {
        Page<BusinessActivityUserVO> page = businessActivityUserService.query(pageNum, pageSize, dto);
        return Result.success(page);
    }

    /**
     * 根据ID查询活动用户关联详情
     * @param id 关联ID
     * @return 活动用户关联详情
     */
    @GetMapping("/{id}")
    public Result<BusinessActivityUserVO> getDetailById(@PathVariable Long id) {
        return Result.success(businessActivityUserService.getDetailById(id));
    }
}